
import { GF_DynamicData } from "../../confg/GF_DynamicData";
import engine from "../../Engine";
import { StatisticsConfig } from "./CCConst";
import { CCGlobal } from "./CCGlobal";



export class CCComFun {

    public static CCLog(...str) {
        engine.log.trace(`[adsfunc] : ${str}`);
    }

    public static StatLog(...str) {
        engine.log.trace(`[GameStatistics] : ${str}`);
        //console.log(`[GameStatistics] : ${str}`);
    }

    public static get statConfig() {
        return StatisticsConfig[CCGlobal.PLATFORM];
    }

    /**
    * 产生随机整数，包含下限值，包括上限值
    * @param {Number} lower 下限
    * @param {Number} upper 上限
    * @return {Number} 返回在下限到上限之间的一个随机整数
    */
    public static random(lower, upper) {
        return Math.floor(Math.random() * (upper - lower + 1)) + lower;
    }

    /**随机打乱 */
    public static shuffle<T>(array: T[]): T[] {
        const shuffledArray = [...array];

        for (let i = shuffledArray.length - 1; i > 0; i--) {
            const j = Math.floor(Math.random() * (i + 1));
            [shuffledArray[i], shuffledArray[j]] = [shuffledArray[j], shuffledArray[i]];
        }

        return shuffledArray;
    }

    /**短震动 */
    public static vibrateShort(type: 'heavy' | 'medium' | 'light') {
        if (!GF_DynamicData.ins.vibrate || engine.cc_debug) { return };

        CCGlobal.API.vibrateShort({ type: type });

    }

    /**长震动 */
    public static vibrateLong() {
        if (!GF_DynamicData.ins.vibrate || engine.cc_debug) { return };
        CCGlobal.API.vibrateLong();
    }




}

